import Vue from 'vue'
import VueRouter from 'vue-router'
import HomeView from '../views/HomeView.vue'


Vue.use(VueRouter)

const routes = [
  {
    path: '/',
    name: 'home',
    component: HomeView
  },
  {
    path: '/about',
    name: 'about',
    // route level code-splitting
    // this generates a separate chunk (about.[hash].js) for this route
    // which is lazy-loaded when the route is visited.
    component: () => import(/* webpackChunkName: "about" */ '../views/AboutView.vue')
  },
  {
    path: '/one',
    name: 'one',
    component: () => import('../views/OneView.vue')
  },
  {
    path: '/two',
    name: 'two',
    component: () => import('../views/TwoView.vue')
  },
  
  {
    path: '/detail',
    name: 'detail',
    component: () => import('../views/DetailView.vue')
  },
  {
    path: '/labels',
    name: 'labels',
    component: () => import('../views/LabelsView.vue')
  },
   {
    path: '/classify',
    name: 'classify',
    component: () => import('../views/ClassifyView.vue')
  },
  {
    path: '/three',
    name: 'three',
    component: () => import('../views/ThreeView.vue')
  }
  ,
  {
    path: '/four',
    name: 'four',
    component: () => import('../views/FourView.vue'),
    meta: { hideNav: true }
  },
  {
    path: '/five',
    name: 'five',
    component: () => import('../views/FiveVIew.vue'),
    meta: { hideNav: true },
    children: [
       {
      path: '', // 空路径表示默认子路由
      redirect: 'six' // 重定向到名为 six 的子路由
    },
      
      {
        path: 'six',
        name: 'six',
        component: () => import('../views/SixView.vue'),
        meta: { hideNav: true }
      },
      {
        path: 'seven',
        name: 'seven',
        component: () => import('../views/SevenView.vue'),
        meta: { hideNav: true }
      },
      
      {
        path: 'eight',
        name: 'eight',
        component: () => import('../views/EightView.vue'),
        meta: { hideNav: true }
      },
      {
        path: 'nine',
        name: 'nine',
        component: () => import('../views/NineView.vue'),
        meta: { hideNav: true }
      },
      
      {
        path: 'ten',
        name: 'ten',
        component: () => import('../views/TenView.vue'),
        meta: { hideNav: true }
      },
    ]
  }
]



const router = new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  routes
})

router.beforeEach((to, from, next) => {
  const token = localStorage.getItem('authorization');
  // 若未登录且访问的不是登录页，则强制跳转登录
  if (!token && to.path !== '/four') {
    next('/four');
  } else {
    next();
  }
});

export default router
